package com.situ.web.service.impl;

import com.situ.web.dao.ITeacherDao;
import com.situ.web.dao.impl.TeacherDaoImpl;
import com.situ.web.entity.Teacher;
import com.situ.web.service.ITeacherService;
import com.situ.web.util.PageInfo;

import java.util.ArrayList;

public class TeacherServiceImpl implements ITeacherService {
    private ITeacherDao teacherDao = new TeacherDaoImpl();

    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        int offset = (pageNo - 1) * pageSize;
        // 得到当前页的数据的集合
        ArrayList<Teacher> list = teacherDao.selectPageList(offset, pageSize);
        // 得到所有数据的数量
        int totalCount = teacherDao.selectTotalCount();
        // 向上取整，算出总的页数
        int totalPage = (int)Math.ceil((double)totalCount / pageSize);
        PageInfo pageInfo = new PageInfo(list, pageNo, totalPage, pageSize);
        System.out.println(pageInfo);
        return pageInfo;
    }
}
